

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sessionbeans.ProfileBeanRemote;

/**
 * Servlet implementation class RequestAbilityServlet
 */
public class RequestAbilityServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RequestAbilityServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		InitialContext context;
		ProfileBeanRemote profileBean;
		String userId = (String) request.getSession().getAttribute("userId");
		String abilityName = request.getParameter("ability");
		String requestOutcome = null;
		
		if (abilityName != null) {
			try {
				context = new InitialContext();
				Object ref = context.lookup("ProfileBeanRemote");
				profileBean = (ProfileBeanRemote) PortableRemoteObject.narrow(ref,ProfileBeanRemote.class);
				requestOutcome = profileBean.sendAbilityRequest(userId, abilityName);
				request.getSession().setAttribute("addoutcome", requestOutcome);
			} catch (NamingException e) {
				System.out.println("Naming Exception");
				e.printStackTrace();
			}
		}
		response.sendRedirect("RequestAbilityPage.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
